package cn.stronglink.asset.module.dam.utils.factorys.req;

import java.util.Map;

import com.alibaba.fastjson.JSON;

import cn.stronglink.asset.module.dam.entity.message.MsgScreenCommand;
import cn.stronglink.asset.module.dam.entity.message.SetNetworkParam1;
import cn.stronglink.asset.module.dam.entity.message.SetNetworkParam2;
import cn.stronglink.asset.module.dam.entity.message.basicMsg.DamMqMessage;
import cn.stronglink.asset.module.dam.entity.message.secondMsg.AwsPostSetNetworkParam1;
import cn.stronglink.asset.module.dam.entity.message.secondMsg.AwsPostSetNetworkParam2;
import cn.stronglink.asset.module.dam.utils.dataJsonUtils.realtime.send.MsgSendUtil;
import cn.stronglink.asset.module.dam.utils.dataJsonUtils.req.send.SendCmdUtil;

public class Factory222SetNetwork {
	private static SetNetworkParam1 setNet1=new SetNetworkParam1();
	private static AwsPostSetNetworkParam1 awsPostdata1=new AwsPostSetNetworkParam1();
	
	private static SetNetworkParam2 setNet2=new SetNetworkParam2();
	private static AwsPostSetNetworkParam2 awsPostdata2=new AwsPostSetNetworkParam2();
	/**
	 * 命令2： 设置网络 先发送读取文本控件内容的指令， 等待数据返回 -->读取： EE B111 0005【画面id】 0004【控件id】
	 * FFFCFFFF
	 */
	public static void sendCommandToGetNetworkParam(MsgScreenCommand msgScreenCommand) {
		// 画面id=5 控件id=1,2,3, 4,5 #设备，子网掩码，网关====目标ip, 目标端口
		msgScreenCommand.setActioncode("getNetParams");
		msgScreenCommand.getAwsPostdata().setCommand(null);
		
		// 发送指令
		System.out.println("设置网络：json串--------》"+JSON.toJSONString(msgScreenCommand));
		MsgSendUtil.sendMsg(SendCmdUtil.topic,JSON.toJSONString(msgScreenCommand));
	}
	
	
	
	/**
	 * 命令2.2 接收返回的指令：格式EE B111 0005 0001~5 0B 数据值 FFFCFFFF
	 */
	public static void getParamAndSendMsg(DamMqMessage msg,Map<Integer,String> values) {// 返回五个数据单元
		/*String cmd2 = cmd.replaceAll("B111", "B110");
		String cmd3 = cmd2.replaceAll("0B", "");
		System.out.println("替换后的数据返回结果：===" + cmd3);*/
		
		//取出数据：发送两次
		String ip=values.get(1);
		String gateway=values.get(2);
		String mask=values.get(3);
		
		String destIp=values.get(4);
		String destPort=values.get(5);
		String rackConverCode=msg.getAwsPostdata().getRackConverCode();
		
		//封装数据： 发送指令
		awsPostdata1.setIp(ip);
		awsPostdata1.setGateway(gateway);
		awsPostdata1.setMask(mask);
		awsPostdata1.setRackConverCode(rackConverCode);
		setNet1.setAwsPostdata(awsPostdata1);
		
		awsPostdata2.setDestIp(destIp);
		awsPostdata2.setDestPort(destPort);
		awsPostdata2.setRackConverCode(rackConverCode);
		setNet2.setAwsPostdata(awsPostdata2);
		
		// 发送消息
		MsgSendUtil.sendMsg(SendCmdUtil.topic, JSON.toJSONString(setNet1));
		MsgSendUtil.sendMsg(SendCmdUtil.topic, JSON.toJSONString(setNet2));
	}


}
